package cn.stylefeng.guns.modular.lx.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.lx.entity.LxSplbZw;
import cn.stylefeng.guns.modular.lx.mapper.LxSplbZwMapper;
import cn.stylefeng.guns.modular.lx.model.params.LxSplbZwParam;
import cn.stylefeng.guns.modular.lx.model.result.LxSplbZwResult;
import  cn.stylefeng.guns.modular.lx.service.LxSplbZwService;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 赵薇
 * @since 2023-12-01
 */
@Service
public class LxSplbZwServiceImpl extends ServiceImpl<LxSplbZwMapper, LxSplbZw> implements LxSplbZwService {

    @Override
    public void add(LxSplbZwParam param){
        LxSplbZw entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(LxSplbZwParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(LxSplbZwParam param){
        LxSplbZw oldEntity = getOldEntity(param);
        LxSplbZw newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public LxSplbZwResult findBySpec(LxSplbZwParam param){
        return null;
    }

    @Override
    public List<LxSplbZwResult> findListBySpec(LxSplbZwParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(LxSplbZwParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(LxSplbZwParam param){
        return param.getLbid();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private LxSplbZw getOldEntity(LxSplbZwParam param) {
        return this.getById(getKey(param));
    }

    private LxSplbZw getEntity(LxSplbZwParam param) {
        LxSplbZw entity = new LxSplbZw();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }


    @Autowired
    private LxSplbZwMapper lxSplbZwMapper;

    @Override
    public ResponseData list2(LxSplbZwParam LxSplbZwParam) {
        List<LxSplbZwResult> list = lxSplbZwMapper.List2(LxSplbZwParam);
        return ResponseData.success(list);
    }
}
